package com.winning.util.excelutil.common.dto;


import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class BaseProtocolOut implements Serializable {

    private boolean success = true;

    private String message;

    private int code;

    private Object data;

    private String timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

    public BaseProtocolOut() {
    }

    public BaseProtocolOut(boolean success, String message, int code, Object data) {
        this.success = success;
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public BaseProtocolOut(boolean success, String message, int code) {
        this.success = success;
        this.message = message;
        this.code = code;
    }

    public BaseProtocolOut(int code, String message, Object data) {
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public BaseProtocolOut(int code, String message) {
        this.message = message;
        this.code = code;
    }

    public static BaseProtocolOut  build(int code, String message, Object data){
        return new BaseProtocolOut(code,message,data);
    }

    public static BaseProtocolOut  error(int code, String message){
        return new BaseProtocolOut(false,message,code);
    }

    public static BaseProtocolOut  error(String message){
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(),message);
    }



    public static BaseProtocolOut  success( String message, Object data){
        return new BaseProtocolOut(true,message, HttpStatus.OK.value(),data);
    }

    public static BaseProtocolOut  success( String message){
        return success( message, null);
    }

    public static BaseProtocolOut  success( Object data){
        return success( "成功", data);
    }

    public  String toJson(){
        return JSON.toJSONString(this);
    }

}
